﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;
using Chenxin.Lib.Utility;

public partial class page_Business_Record_ArchiveDetailInfo :PageBase
{
    string strRecordId = string.Empty;

    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (string.IsNullOrEmpty(Request.Params["RecordId"]))
            {
                Response.Redirect("~/page/errorpage.aspx?msg=非法信息", true);
            }
            if (!IsPostBack)
            {
                strRecordId = Request.Params["RecordId"].ToString().Trim();
                this.hidRecordId.Value = strRecordId;
                Chenxin.Lib.Business.Entity.t_Business_Record_BaseInfo model = Chenxin.Lib.Business.DAL.t_Business_Record_BaseInfo.GetModel(new Guid(strRecordId));
                BindArchiveTable(model);
            }
        }
        catch (Exception ex)
        {
            Response.Redirect("~/page/errorpage.aspx?msg=" +  Server.UrlEncode( ex.Message) + "", true);
        }
    }

    private void BindArchiveTable(Chenxin.Lib.Business.Entity.t_Business_Record_BaseInfo model)
    {
        StringBuilder sb = new StringBuilder();

        //报备详情-房源信息Table
        sb.Append("<table width=\"100%\" cellspacing=\"1\" class=\"tabsorternew table_archive\">");
        sb.Append("<thead>");
        sb.Append("<tr>");
        sb.Append("<th colspan=\"6\" style='text-align:center;'><span>房源信息</span></th>");
        sb.Append("</tr>");
        sb.Append("</thead>");
        sb.Append("<tbody>");
        sb.Append("<tr>");
        sb.AppendFormat("<th style=\"text-align:right;\">房源地址：</th><td colspan=\"3\">{0}</td><th style=\"text-align:right;\">产证编号：</th><td>{1}</td>", model.HouseAddress, model.PropertyCode);
        sb.Append("</tr>");
        sb.Append("<tr>");
        sb.AppendFormat("<th style=\"text-align:right;\">建筑类型：</th><td colspan=\"3\">{0}</td><th style=\"text-align:right;\">房屋用途：</th><td>{1}</td>", model.BuildingType, model.HouseUse);
        sb.Append("</tr>");
        sb.Append("<tr>");
        sb.AppendFormat("<th style=\"width:100px;text-align:right;\">建筑面积：</th><td style=\"width:175px;\">{0} ㎡</td><th style=\"width:100px;text-align:right;\">楼层：</th><td style=\"width:175px;\">{2}楼</td><th style=\"width:100px;text-align:right;\">竣工时间：</th><td>{1}年</td>", model.BuildingArea, model.CompleteYear, model.Cur_Floor);
        sb.Append("</tr>");
        sb.Append("<tr>");
        sb.AppendFormat("<th style=\"text-align:right;\">房源所属人：</th><td colspan=\"3\">{0}</td><th style=\"text-align:right;\">房源所属部门：</th><td>{1}</td>", model.BelongUserName, model.BelongUserDepartmentName);
        sb.Append("</tr>");
        sb.Append("</tbody>");
        sb.Append("</table>");
        sb.Append("<div class=\"clear\" style=\"height:10px\"></div>");

        //报备详情-报备信息Table
        sb.Append("<table width=\"100%\" cellspacing=\"1\" class=\"tabsorternew table_archive\">");
        sb.Append("<thead>");
        sb.Append("<tr>");
        sb.Append("<th colspan=\"6\" style='text-align:center;'><span>报备信息</span></th>");
        sb.Append("</tr>");
        sb.Append("</thead>");
        sb.Append("<tbody>");
        sb.Append("<tr>");
        sb.AppendFormat("<th style=\"width:100px;text-align:right;\">签约类型：</th><td style=\"width:175px;\">{0}</td><th style=\"width:100px;text-align:right;\">签合同时间：</th><td style=\"width:175px;\">{1:yyyy-MM-dd HH:mm}\r\n</td><th style=\"width:100px;text-align:right;\">签贷款时间：</th><td>{2:yyyy-MM-dd HH:mm}</td>", model.BargainType, model.BargainTime, model.LoanTime);
        sb.Append("</tr>");
        sb.Append("<tr>");
        sb.AppendFormat("<th style=\"text-align:right;\">报备人：</th><td >{0}</td><th style=\"text-align:right;\">报备部门：</th><td>{1}</td><th style=\"text-align:right;\">联系电话：</th><td>{2}</td>", model.Employee, model.DepartName, model.Mobile);
        sb.Append("</tr>");
        sb.Append("<tr>");
        sb.AppendFormat("<th style=\"text-align:right;\">签约地点：</th><td>{0}</td><th style=\"text-align:right;\">签约人：</th><td>{1}</td><th style=\"text-align:right;\">合同归属：</th><td>{2}-{3}</td>", model.WorkDepartName, model.WorkPersonName,model.BargainCityName,model.BargainCompanyName);
        sb.Append("</tr>");
        sb.Append("<tr>");
        sb.AppendFormat("<th style=\"text-align:right;\">特殊情况：</th><td colspan=\"5\" style=\"width:185px\">{0}</td>", model.SpecialInfo);
        sb.Append("</tr>");
        sb.Append("</tbody>");
        sb.Append("</table>");
        sb.Append("<div class=\"clear\" style=\"height:10px\"></div>");

        //合同详情-交易信息Table
        sb.Append("<table width=\"100%\" cellspacing=\"1\" class=\"tabsorternew table_archive\">");
        sb.Append("<thead>");
        sb.Append("<tr>");
        sb.Append("<th colspan=\"4\" style='text-align:center;'><span>交易信息</span></th>");
        sb.Append("</tr>");
        sb.Append("</thead>");
        sb.Append("<tbody>");
        sb.Append("<tr>");
        sb.AppendFormat("<th style=\"width:100px;text-align:right;\">合同价：</th><td style=\"width:315px;\">{0}</td><th style=\"width:100px;text-align:right;\">装修补偿款：</th><td>{1}</td>", model.TotalPrice, model.FitPrice);
        sb.Append("</tr>");
        sb.Append("<tr>");
        sb.AppendFormat("<th style=\"text-align:right;\">抵押情况：</th><td>{0}</td><th style=\"text-align:right;\">是否公证：</th><td>{1}</td>", model.MortgageInfo, model.FariInfo);
        sb.Append("</tr>");
        sb.Append("<tr>");
        sb.AppendFormat("<th style=\"text-align:right;\">还贷时间：</th><td>{0}</td><th style=\"text-align:right;\">租约：</th><td>{1}</td>", model.PayLoanDay, model.FairPoint);
        sb.Append("</tr>");
        sb.Append("<tr>");
        sb.AppendFormat("<th style=\"text-align:right;\">维修基金：</th><td>{0}</td><th style=\"text-align:right;\">交房时间：</th><td>{1}</td>", model.RepairFund, model.GiveHouseTime);
        sb.Append("</tr>");
        sb.Append("<tr>");
        sb.AppendFormat("<th style=\"text-align:right;\">付款方式：</th><td>{0}</td><th style=\"text-align:right;\">过户日期：</th><td>{1}</td>", model.PayMode,model.TransferDate.ToString().Length>0?model.TransferDate.Value.ToShortDateString():"");
        sb.Append("</tr>");
        sb.Append("<tr>");
        sb.AppendFormat("<th style=\"text-align:right;\">固定装修附送设&nbsp;&nbsp;&nbsp;&nbsp;<br>施设备家电家具：</th><td colspan=\"3\">{0}</td>", model.Remark);
        sb.Append("</tr>");
        sb.Append("</tbody>");
        sb.Append("</table>");
        sb.Append("<div class=\"clear\" style=\"height:10px\"></div>");

        //报备详情-出售方信息Table
        string strWhere = string.Format("MainId = '{0}'", model.RecordId);
        DataSet ds = Chenxin.Lib.Business.DAL.t_Business_Record_SubInfo1.GetList(strWhere);
        sb.Append("<table width=\"100%\" cellspacing=\"1\" class=\"tabsorternew table_archive\">");
        sb.Append("<thead>");
        sb.Append("<tr>");
        sb.Append("<th colspan=\"4\" style='text-align:center;'><span>出售方信息</span></th>");
        sb.Append("</tr>");
        sb.Append("</thead>");
        sb.Append("<tbody>");
        sb.Append("<tr>");
        sb.AppendFormat("<th style=\"width:100px;text-align:right;\">地址：</th><td style=\"width:315px;\">{0}</td><th style=\"width:100px;text-align:right;\">电话：</th><td>{1}</td>", model.VenderAddress, model.VenderTel);
        sb.Append("</tr>");
        sb.Append("<tr><th colspan=\"2\" style='text-align:center;'>姓名</th><th colspan=\"2\" style='text-align:center;'>身份证</th></tr>");
        if (ds != null && ds.Tables[0].Rows.Count != 0)
        {
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                sb.Append("<tr>");
                sb.AppendFormat("<td colspan=\"2\">{0}</td><td colspan=\"2\">{1}</td>", dr["CustomerName"], dr["IDNum"]);
                sb.Append("</tr>");
            }
        }
        sb.Append("</tbody>");
        sb.Append("</table>");
        sb.Append("<div class=\"clear\" style=\"height:10px\"></div>");

        //报备详情-买受方信息Table
        ds = null;
        ds = Chenxin.Lib.Business.DAL.t_Business_Record_SubInfo2.GetList(strWhere);
        sb.Append("<table width=\"100%\" cellspacing=\"1\" class=\"tabsorternew table_archive\">");
        sb.Append("<thead>");
        sb.Append("<tr>");
        sb.Append("<th colspan=\"6\" style='text-align:center;'><span>买受方信息</span></th>");
        sb.Append("</tr>");
        sb.Append("</thead>");
        sb.Append("<tbody>");
        sb.Append("<tr>");
        sb.AppendFormat("<th style=\"width:100px;text-align:right;\">地址：</th><td colspan=\"2\">{0}</td><th style=\"width:100px;text-align:right;\">电话：</th><td colspan=\"2\">{1}</td>", model.BuyerAddress, model.BuyerTel);
        sb.Append("</tr>");
        sb.Append("<tr><th style='text-align:center;'>姓名</th><th style='text-align:center;'>身份证</th><th style='text-align:center;'>公积金账号</th><th style='text-align:center;'>配偶姓名</th><th style='text-align:center;'>配偶身份证</th><th style='text-align:center;'>配偶公积金</th></tr>");
        if (ds != null && ds.Tables[0].Rows.Count != 0)
        {
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                sb.Append("<tr>");
                sb.AppendFormat("<td>{0}</td><td style=\"width:155px;\">{1}</td><td style=\"width:155px;\">{2}</td>", dr["CustomerName"], dr["IDNum"], dr["GJJNum"]);
                //sb.Append("</tr>");
                //sb.Append("<tr>");
                sb.AppendFormat("<td>{0}</td><td style=\"width:155px;\">{1}</td><td>{2}</td>", dr["SpousesName"], dr["SpousesIDNum"], dr["SpousesGJJNum"]);
                sb.Append("</tr>");
            }
        }
        sb.Append("</tbody>");
        sb.Append("</table>");
        sb.Append("<div class=\"clear\" style=\"height:10px\"></div>");

        //报备详情-贷款回复Table
        sb.Append("<table width=\"100%\" cellspacing=\"1\" class=\"tabsorternew table_archive\">");
        sb.Append("<thead>");
        sb.Append("<tr>");
        sb.Append("<th colspan=\"4\" style='text-align:center;'><span>贷款回复</span></th>");
        sb.Append("</tr>");
        sb.Append("</thead>");
        sb.Append("<tbody>");
        sb.Append("<tr>");
        sb.AppendFormat("<th style=\"width:100px;text-align:right;\">评估价：</th><td style=\"width:315px;\">{0}</td><th style=\"width:100px;text-align:right;\">资信程度：</th><td>{1}</td>", model.EvaluatePrice, model.LonggevityLevel);
        sb.Append("</tr>");
        sb.Append("<tr>");
        sb.AppendFormat("<th style=\"text-align:right;\">贷款银行：</th><td>{0}</td><th style=\"text-align:right;\">评估公司：</th><td>{1}</td>", model.LoanBank, model.EvaluateCompany);
        sb.Append("</tr>");
        sb.Append("<tr>");
        sb.AppendFormat("<th style=\"text-align:right;\">公积金贷款金额：</th><td>{0}</td><th style=\"text-align:right;\">公积金贷款年限：</th><td>{1}</td>", model.FundLoanPrice, model.FundLoanEndYear);
        sb.Append("</tr>");
        sb.Append("<tr>");
        sb.AppendFormat("<th style=\"text-align:right;\">商业贷款金额：</th><td>{0}</td><th style=\"text-align:right;\">商业贷款年限：</th><td>{1}</td>", model.BusinessLoanPrice, model.BusinessLoanEndYear);
        sb.Append("</tr>");
        sb.Append("<tr>");
        sb.AppendFormat("<th style=\"text-align:right;\">贷款回复描述：</th><td colspan=\"3\">{0}</td>", model.LoanAnswerContent);
        sb.Append("</tr>");
        sb.Append("</tbody>");
        sb.Append("</table>");
        sb.Append("<div class=\"clear\" style=\"height:10px\"></div>");

        //报备详情-法务回复Table
        sb.Append("<table width=\"100%\" cellspacing=\"1\" class=\"tabsorternew table_archive\">");
        sb.Append("<thead>");
        sb.Append("<tr>");
        sb.Append("<th colspan=\"2\" style='text-align:center;'><span>法务回复</span></th>");
        sb.Append("</tr>");
        sb.Append("</thead>");
        sb.Append("<tbody>");
        sb.Append("<tr>");
        sb.AppendFormat("<th style=\"width:100px;text-align:right;\">法务回复描述：</th><td>{0}</td>", model.LawAnswerContent);
        sb.Append("</tr>");
        sb.Append("</tbody>");
        sb.Append("</table>");
        sb.Append("<div class=\"clear\" style=\"height:10px\"></div>");

        //报备详情-办证回复Table
        sb.Append("<table width=\"100%\" cellspacing=\"1\" class=\"tabsorternew table_archive\">");
        sb.Append("<thead>");
        sb.Append("<tr>");
        sb.Append("<th colspan=\"2\" style='text-align:center;'><span>办证回复</span></th>");
        sb.Append("</tr>");
        sb.Append("</thead>");
        sb.Append("<tbody>");
        sb.Append("<tr>");
        sb.AppendFormat("<th style=\"width:100px;text-align:right;\">办证回复描述：</th><td>{0}</td>", model.ApplyDocAnswerContent);
        sb.Append("</tr>");
        sb.Append("</tbody>");
        sb.Append("</table>");
        sb.Append("<div class=\"clear\" style=\"height:10px\"></div>");

        //报备详情-日常回复Table
        string FieldList = "*";
        string TableFieldList = "a.*,b.FilePath,b.FileName";
        strWhere = string.Format("a.MainId = '{0}'", model.RecordId);
        string TableName = "t_Business_Record_SubInfo3 as a left join t_Business_Record_SubInfo4 as b on b.AnswerId = a.RecordId ";
        ds = null;
        ds = Chenxin.Lib.Business.DAL.t_Business_Record_SubInfo3.GetList(1, 999, "CreateTime desc", TableName, strWhere, FieldList, TableFieldList, true);
        sb.Append("<table width=\"100%\" cellspacing=\"1\" class=\"tabsorternew table_archive\">");
        sb.Append("<thead>");
        sb.Append("<tr>");
        sb.Append("<th colspan=\"4\"><span>报备详情-日常回复</span></th>");
        sb.Append("</tr>");
        sb.Append("</thead>");
        sb.Append("<tbody>");
        sb.Append("<tr>");
        sb.Append("<th style=\"width:100px;\">回复人</th><th style=\"width:130px;\">回复时间</th><th style=\"width:320px\">回复内容</th><th>附件</th>");
        sb.Append("</tr>");
        if (ds != null && ds.Tables[0].Rows.Count != 0)
        {
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                sb.Append("<tr>");
                sb.AppendFormat("<td>{0}</td><td>{1}</td><td>{2}</td>", dr["CreateUserName"], dr["CreateTime"], dr["AnswerContent"]);
                string pathname = dr["FileName"].ToString();
                if (!string.IsNullOrEmpty(pathname) && pathname.Length > 20)
                {
                    pathname = pathname.Substring(0, 20) + "...";
                }
                sb.AppendFormat("<td><span><a id=\"abtnreply\" href=\"/service/Download.ashx?file=/{0}\" title=\"{1}\">{2}</a></span><br></td>", Constants.FilePath_ArchiveReply + dr["FilePath"], dr["FileName"], pathname);

                sb.Append("</tr>");
            }
        }
        sb.Append("</tbody>");
        sb.Append("</table>");
        sb.Append("<div class=\"clear\" style=\"height:10px\"></div>");

        //附件一览Table
        strWhere = string.Format("BargainId = '{0}' Order By CreateTime Desc", model.RecordId);
        ds = null;
        ds = Chenxin.Lib.Business.DAL.t_Business_Record_SubInfo4.GetList(strWhere);
        sb.Append("<table width=\"100%\" cellspacing=\"1\" class=\"tabsorternew table_archive\">");
        sb.Append("<thead>");
        sb.Append("<tr>");
        sb.Append("<th colspan=\"3\"><span>附件一览</span></th>");
        sb.Append("</tr>");
        sb.Append("</thead>");
        sb.Append("<tbody>");
        sb.Append("<tr>");
        sb.Append("<th style=\"width:100px;\">上传人</th><th style=\"width:130px;\">上传时间</th><th>附件名称</th>");
        sb.Append("</tr>");
        if (ds != null && ds.Tables[0].Rows.Count != 0)
        {
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                sb.Append("<tr>");
                sb.AppendFormat("<td>{0}</td><td>{1}</td>", dr["CreateUserName"], dr["CreateTime"]);
                string pathname = dr["FileName"].ToString();
                if (!string.IsNullOrEmpty(pathname) && pathname.Length > 40)
                {
                    pathname = pathname.Substring(0, 40) + "...";
                }
                sb.AppendFormat("<td><span><a id=\"abtnreply\" href=\"/service/Download.ashx?file=/{0}\" title=\"{1}\">{2}</a></span><br></td>", Constants.FilePath_ArchiveReply + dr["FilePath"], dr["FileName"], pathname);
                sb.Append("</tr>");
            }
        }
        sb.Append("</tbody>");
        sb.Append("</table>");
        sb.Append("<div class=\"clear\" style=\"height:10px\"></div>");

        sb.Append("<div style=\"text-align:center\"><a href='/page/Business_Record/ShowListArchive.aspx' title='返回' id='areturnarchive'><span>返回</span></a></div>");
        this.ltArchiveDetailInfo.Text = sb.ToString();
    }

}
